package com.example.controller;

import com.example.pojo.*;
import com.example.pojo.DTO.EmpDTO;
import com.example.pojo.VO.EmpVO;
import com.example.service.EmpService;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

/**
 * 员工管理
 */
@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;
    /**
     * 分页查询
     */
    @GetMapping
    public Result page(EemQueryParam empQueryParam){
        log.info("分页查询: {}", empQueryParam);
        PageResult<EmpVO> pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }
    @PostMapping
    public Result save(@RequestBody EmpDTO  empDTO){
        log.info("新增员工: {}", empDTO);
        empService.save(empDTO);
        return Result.success();
    }
    /**
     * 获取员工信息
     */
    @GetMapping("/{id}")
    public Result getEmpInfo(@PathVariable Integer id){
        log.info("根据ID查询员工信息: {}", id);
       EmpDTO empDTO = empService.getEmpInfoById(id);
       return Result.success(empDTO);
    }

    @PutMapping
    public Result update(@RequestBody EmpDTO empDTO){
        log.info("修改员工: {}", empDTO);
        empService.update(empDTO);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工: {}", ids);
        empService.delete(ids);
        return Result.success();
    }
}
